layui.use(['request','table'], function () {
    "use strict";
    let request = layui.request,
        table = layui.table;
    (function () {
        hashChangeFire();
        <!--js实现的简单路由-->
        if (("onhashchange" in window) && ((typeof document.documentMode === "undefined") || document.documentMode == 8)) {
            // 浏览器支持onhashchange事件
            window.onhashchange = hashChangeFire;  // 对应新的hash执行的操作函数
            window.onbeforeunload = hashChangeFire; // 监听页面刷新事件
        } else {
            // 不支持则用定时器检测的办法
            setInterval(function () {
                var ischanged = isHashChanged();  // TODO，检测hash值或其中某一段是否更改的函数
                if (ischanged) {
                    hashChangeFire();  // TODO，对应新的hash执行的操作函数
                }
            }, 150);
        }
    }());
    function hashChangeFire(e) {
        let username = layui.data('userInfo').username;
        if (username) {
            request({url: 'auth/check'}).then(res => {
                if (username !== res) {
                    localStorage.clear();
                    window.location = "login.html";
                }
            }).catch(e => {
                layer.msg(e, function () {
                    localStorage.clear();
                    window.location = "login.html";
                });
            });
        } else {
            window.location = "login.html";
        }
    }
});
